/* file.c
 *      Test program for file input and output
 *
 *      Intended to test file input and output, as well as exceptions
 */
#include "syscall.h"

#define DIM 31

int main() {
    char fname[] = "test.txt";
    char txtToWrite[] = "1234567890123456789012345678901";

    //create the file, write to it then close it
    Create(fname);
    OpenFileId f = Open(fname);
    Write(txtToWrite, DIM, f);
    Close(f);

    //now read from the file and test the text contained
    char buf[DIM];
    OpenFileId f2 = Open(fname);
    Read(buf, DIM, f2);
    Close(f2);

    int i;
    int pass = 0;
    for(i = 0; i < DIM; i++) {
        if(txtToWrite[i] != buf[i]) {
            pass = 1;
        }
    }

    //test failure
    if(pass == 1) {
        Exit(1);
    } else {
        Exit(0);
    }
}
